$(function() {

	var test = window.location.pathname;
	//alert(test);
	var sts=test.split("/"); 
	var turl="/" + sts[1] +"/set/role/getMenuByKey";
	var postData="menuKey=" +encodeURIComponent(test);
	 $.ajax({
           type: "POST",
           url: turl,
           data: postData,
           contentType: "application/x-www-form-urlencoded;charset=UTF-8",
           async: true, // 同步  true 异步。默认是异步
           dataType: 'json',
           error: function(resultdata) {
           	//layer.closeAll();
           },
           success: function(resultdata) {
          // 	layer.closeAll();
        	   initButton(resultdata);
           }
       });
});

function initButton(resultdata){
    if(resultdata.returnCode=="0000"){              	   
        $(".buttonrole").each(function () {
     	   var btnName=$(this).attr('name');
     	   if(btnName==undefined){
     		   $(this).hide();
     		   return;
     	   }
     	  
     	   var btnText=getButtonName(resultdata.showbutton,btnName);
     	   if(btnText==''){
     	    	$(this).hide();
     	    }else{
     	    	$(this).show();
     	    	if($(this).is('input')){
     	    		$(this).val(btnText);
     	    	}else{
     	    		$(this).html(btnText);
     	    	}
     	    	
     	    }
        });

    }
}

function getButtonName(showButtonJson,btnText){
	var result="";
	
	if(showButtonJson.length==0){
		return "";
	}
	for (var i = 0;i < showButtonJson.length;i++ ) {
		var data=showButtonJson[i];
		var btnKey=data.btnkey;
        var btnName=data.btnname;
        if(btnText==btnKey){
        	return btnName;
        }
	}
	return result;
}